package com.example.myapplication0523.activity;

import static android.view.View.VISIBLE;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

import com.example.myapplication0523.R;
import com.example.myapplication0523.adapter.ViewPagerAdapter;
import com.example.myapplication0523.fragment.AlipayHomeFragment;
import com.example.myapplication0523.fragment.AlipayMessageFragment;
import com.example.myapplication0523.fragment.AlipayMineFragment;
import com.example.myapplication0523.fragment.AlipayMoneyFragment;
import com.example.myapplication0523.fragment.AlipayVideoFragment;
import com.example.myapplication0523.fragment.ToutiaoHomeFragment;
import com.example.myapplication0523.fragment.ToutiaoMallFragment;
import com.example.myapplication0523.fragment.ToutiaoMineFragment;
import com.example.myapplication0523.fragment.ToutiaoVideoFragment;
import com.example.myapplication0523.view.MyViewPager;

import java.util.ArrayList;
import java.util.List;

public class AlipayActivity extends FragmentActivity implements View.OnClickListener {
    private LinearLayout homeLay;
    private LinearLayout videoLay;
    private LinearLayout messageLay;
    private LinearLayout moneyLay;
    private LinearLayout mineLay;
    private TextView homeTv;
    private TextView moneyTv;
    private TextView videoTv;
    private TextView messageTv;
    private TextView mineTv;
    private MyViewPager viewpager;
    private ImageView homeIv;
    private GridView gv;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alipay);
        initView(); //配置组件
        initData(); //配置数据
    }

    /**
     * 配置数据
     */
    private void initData() {
        List<Fragment> list= new ArrayList<>();
        list.add(new AlipayHomeFragment());
        list.add(new AlipayMoneyFragment());
        list.add(new AlipayVideoFragment());
        list.add(new AlipayMessageFragment());
        list.add(new AlipayMineFragment());
        ViewPagerAdapter adapter= new ViewPagerAdapter(getSupportFragmentManager(), list);
        viewpager.setAdapter(adapter);
    }

    /**
     * 配置组件
     */
    private void initView() {
        homeIv= findViewById(R.id.iv_home);
        homeLay= findViewById(R.id.layout_home);
        moneyLay= findViewById(R.id.layout_money);
        videoLay= findViewById(R.id.layout_video);
        messageLay= findViewById(R.id.layout_message);
        mineLay= findViewById(R.id.layout_mine);

        homeTv= findViewById(R.id.tv_home);
        moneyTv= findViewById(R.id.tv_money);
        videoTv= findViewById(R.id.tv_video);
        messageTv= findViewById(R.id.tv_message);
        mineTv= findViewById(R.id.tv_mine);

        viewpager= findViewById(R.id.viewpager);
        gv= findViewById(R.id.home_gv);

        homeLay.setOnClickListener(this);
        videoLay.setOnClickListener(this);
        moneyLay.setOnClickListener(this);
        messageLay.setOnClickListener(this);
        mineLay.setOnClickListener(this);

        homeLay.setSelected(true);
        homeTv.setTextColor(Color.RED);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.layout_home:
                moneyLay.setSelected(false);
                videoLay.setSelected(false);
                messageLay.setSelected(false);
                mineLay.setSelected(false);
                moneyTv.setTextColor(Color.parseColor("#333333"));
                videoTv.setTextColor(Color.parseColor("#333333"));
                messageTv.setTextColor(Color.parseColor("#333333"));
                mineTv.setTextColor(Color.parseColor("#333333"));
                viewpager.setCurrentItem(0);
                homeIv.setImageResource(R.mipmap.icon_alipay);
                homeTv.setVisibility(View.GONE);
                break;
            case R.id.layout_money:
                moneyLay.setSelected(true);
                videoLay.setSelected(false);
                messageLay.setSelected(false);
                mineLay.setSelected(false);
                homeTv.setTextColor(Color.parseColor("#333333"));
                moneyTv.setTextColor(Color.parseColor("#00BFFF"));
                videoTv.setTextColor(Color.parseColor("#333333"));
                messageTv.setTextColor(Color.parseColor("#333333"));
                mineTv.setTextColor(Color.parseColor("#333333"));
                viewpager.setCurrentItem(1);
                homeIv.setImageResource(R.mipmap.icon_home_unselected);
                homeTv.setVisibility(View.VISIBLE);
                break;
            case R.id.layout_video:
                moneyLay.setSelected(false);
                videoLay.setSelected(true);
                messageLay.setSelected(false);
                mineLay.setSelected(false);
                homeTv.setTextColor(Color.parseColor("#333333"));
                moneyTv.setTextColor(Color.parseColor("#333333"));
                videoTv.setTextColor(Color.parseColor("#00BFFF"));
                messageTv.setTextColor(Color.parseColor("#333333"));
                mineTv.setTextColor(Color.parseColor("#333333"));
                viewpager.setCurrentItem(2);
                homeIv.setImageResource(R.mipmap.icon_home_unselected);
                homeTv.setVisibility(View.VISIBLE);
                break;
            case R.id.layout_message:
                moneyLay.setSelected(false);
                videoLay.setSelected(false);
                messageLay.setSelected(true);
                mineLay.setSelected(false);
                homeTv.setTextColor(Color.parseColor("#333333"));
                moneyTv.setTextColor(Color.parseColor("#333333"));
                videoTv.setTextColor(Color.parseColor("#333333"));
                messageTv.setTextColor(Color.parseColor("#00BFFF"));
                mineTv.setTextColor(Color.parseColor("#333333"));
                viewpager.setCurrentItem(3);
                homeIv.setImageResource(R.mipmap.icon_home_unselected);
                homeTv.setVisibility(View.VISIBLE);
                break;
            case R.id.layout_mine:
                moneyLay.setSelected(false);
                videoLay.setSelected(false);
                messageLay.setSelected(false);
                mineLay.setSelected(true);
                homeTv.setTextColor(Color.parseColor("#333333"));
                moneyTv.setTextColor(Color.parseColor("#333333"));
                videoTv.setTextColor(Color.parseColor("#333333"));
                messageTv.setTextColor(Color.parseColor("#333333"));
                mineTv.setTextColor(Color.parseColor("#00BFFF"));
                viewpager.setCurrentItem(4);
                homeIv.setImageResource(R.mipmap.icon_home_unselected);
                homeTv.setVisibility(View.VISIBLE);
                break;
        }
    }
}
